package temp2;

import java.io.IOException;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class SenderCountMapper extends Mapper<LongWritable, Text, Text, Text> {

    private Text sender = new Text();
    private final static Text dummy = new Text("1"); // 使用常量值减少对象创建

    @Override
    protected void map(LongWritable key, Text value, Context context)
            throws IOException, InterruptedException {

        // 跳过CSV文件头行（如果有）
        if (key.get() == 0 && value.toString().contains("header")) {
            return;
        }

        // 分割CSV行
        String[] columns = value.toString().split(",");

        // 确保有足够列且B列不为空（假设B列是第2列，索引1）
        if (columns.length > 1 && !columns[1].trim().isEmpty()) {
            sender.set(columns[1].trim()); // 去除前后空格
            context.write(sender, dummy);
        }
    }
}